<?php
error_reporting(0);
$isadmin=1;    
include '../comm/config.php';	
include 'check.php';

if($_POST['smtphost']!=''){
	$from=$_POST['smtpuser'];
	$to=$_POST['test_email'];
	$usepassword=$_POST['smtppw'];
	$smtp=$_POST['smtphost'];
	$title=WEBTITLE.'邮件测试';
	$html='这是'.WEBTITLE.'发送的一封测试邮件';
    echo mail_send($to, $title, $html,$from, $usepassword, $smtp);
	exit;
}

function update_sql($table,$field_arr,$where,$xs,$alert=0){ //$xs 0表示更新 1表示同加  2表示同减,$alert默认为0,1表示打印sql语句,2表示先执行在打印
    global $BIAOTOU;
	$sql="";
	foreach($field_arr as $k=>$v){
		if($xs==0){
		    $sql="`$k`='$v',".$sql;
		}
		elseif($xs==1){
		    $sql="`$k`=`$k`+'$v',".$sql;
		}
		elseif($xs==2){
		    $sql="`$k`=`$k`-'$v',".$sql;
		}
	}
	$sql=substr($sql,0,strlen($sql)-1);
	$sql="update $BIAOTOU$table set $sql where $where;";
	if($alert==0){
		$query=mysql_query($sql);
		if($query==''){
		    echo mysql_error();exit;
		}
	}
	elseif($alert==1){
		echo $sql;
	}
	elseif($alert==2){
		mysql_query($sql);
	    echo $sql; 
	}
}

if(array_key_exists('smtp_open',$_POST)){
	$field_arr=$_POST;
    update_sql('websetting',$field_arr,'Id=1',0,0);
    admin_log('保存邮件服务器设置'); 
	echo "<script language=javascript>window.location='smtpset.php';</script>";
}

mysql_close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>管理中心</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
<script src="js/jquery.js"></script>
<script>
function checkEmailJihuo(){
    var v=$("input[name='reg_send_email'][type='radio']:checked").val();
	if(v==0){
	    $("input[name='reg_send_email']:first").attr('checked', 'true');
		alert('开启此项，会员注册发送邮件必须同时开启');
	}
	
}
$(function(){
	$('#testEmail').click(function(){
		var smtphost=$('#smtphost').val(); 
		var smtpuser=$('#smtpuser').val(); 
		var smtppw=$('#smtppw').val(); 
		var test_email=$('#test_email').val(); 
		$sub=$(this);
		$sub.attr({'disabled':true});
		if(smtphost=='' || smtpuser=='' || smtppw=='' || test_email==''){
			alert('缺少信息');
			$sub.attr({'disabled':false});
		}
		else{
			$.post('smtpset.php',{'smtphost':smtphost,'smtpuser':smtpuser,'smtppw':smtppw,'test_email':test_email},function(data){
			    alert(data); 
			    $sub.attr({'disabled':false});
		    });
	    }
    });
});
                    </script>
</head>

<body topmargin="5" leftmargin="0">
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="282" valign="top"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td>
          <table cellspacing="0" width="100%" height="207" style="border:1px  solid #DCEAF7;">
            <tr>
              <td height="30" colspan="2" bgcolor="E9F2FB" class="bigtext"><strong>&nbsp;<img src="images/arrow.gif" width="16" height="22" align="absmiddle" />电子邮件设置</strong>（确认支持smtp）</strong></td>
            </tr>
            <tr>
              <td width="100%" colspan="2" valign="top"><table width="100%" height="300" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td valign="top"><form id="form1" name="form1" method="post" action="smtpset.php">
                    <table width="100%"  align="center" border=1 cellpadding=0 cellspacing=0 style="border-collapse: collapse" bordercolor="#dddddd">
					   <tr>
                        <td width="200" height="30" align="right" class="bigtext">smtp服务开关：</td>
                  <td height="30" class="bigtext">&nbsp;  <select name="smtp_open">
                            <option value="on" <?php if(SMTPOPEN=="on") echo "selected";?>>开启</option>
                            <option value="off" <?php if(SMTPOPEN=="off") echo "selected";?>>关闭</option>
                                                    </select>
                           关闭此服务所有的邮件服务都会失效 </td>
                      </tr>
                      <tr>
                        <td width="200" height="30" align="right" class="bigtext">注册会员邮件：</td>
                      <td height="30" class="bigtext">&nbsp;<label><input name="reg_send_email" type="radio" value="1" <?php if(REGSENDEMAIL==1){?> checked="checked" <?php }?> />开启</label>&nbsp;<label><input name="reg_send_email" type="radio" value="0" <?php if(REGSENDEMAIL==0){?> checked="checked" <?php }?> />关闭</label>
                      </td>
                      </tr>
                      <tr>
                        <td width="200" height="30" align="right" class="bigtext">是否需要邮件激活：</td>
                      <td height="30" class="bigtext">&nbsp;<label><input name="email_jihuo" onclick="checkEmailJihuo()" type="radio" value="1" <?php if(EMAILJIHUO==1){?> checked="checked" <?php }?> />开启</label>&nbsp;<label><input name="email_jihuo" type="radio" value="0" <?php if(EMAILJIHUO==0){?> checked="checked" <?php }?> />关闭</label>
                      (开启此项后，网站会向会员填写邮箱发送确认邮件，确认后，会员才可登陆)</td>
                      </tr>
                      
                      <tr>
                        <td width="200" height="30" align="right" class="bigtext">提现成功邮件：</td>
                      <td height="30" class="bigtext">&nbsp;<label><input name="tixian_send_email" type="radio" id="tixian_send_email" value="1" <?php if(TIXIANSENDEMAIL==1){?> checked="checked" <?php }?> />开启</label>&nbsp;<label><input name="tixian_send_email" type="radio" id="reg_send_email" value="0" <?php if(TIXIANSENDEMAIL==0){?> checked="checked" <?php }?> />关闭</label>
                      </td>
                      </tr>
                      
					    <tr>
                        <td width="200" height="30" align="right" class="bigtext">smtp服务器地址：</td>
                      <td height="30" class="bigtext">&nbsp;<input name="smtp_host" type="text" id="smtphost" value="<?php echo SMTPHOST;?>" size="20" maxlength="30" class="btn3" style="width:200px" />
                          如：smtp.qq.com ，smtp.126.com</td>
                      </tr>
					    <tr>
                        <td width="200" height="30" align="right" class="bigtext">smtp服务器用户名：</td>
                      <td height="30" class="bigtext">&nbsp;<input name="smtp_user" type="text" id="smtpuser" value="<?php echo SMTPUSER;?>" size="20" maxlength="30" class="btn3" style="width:200px" />
                          您的邮箱用户名，如service@duoduo123.com</td>
                      </tr>
					    <tr>
                        <td width="200" height="30" align="right" class="bigtext">smtp服务器密码：</td>
                        <td height="30" class="bigtext">&nbsp;<input name="smtp_pw" type="password" id="smtppw" value="<?php echo SMTPPW;?>" size="20" maxlength="30" class="btn3" style="width:200px" /> 
                        您的邮箱密码                        </td>
                      </tr>
                      <tr>
                        <td width="200" height="30" align="right" class="bigtext">测试邮箱：</td>
                        <td height="30" class="bigtext">&nbsp;<input type="text" id="test_email" value="" size="20" maxlength="30" class="btn3" style="width:200px" /> 
                        <input type="button" value="测试邮件发送"  id="testEmail" />                      </td>
                      </tr> 					  
                      <tr>
                        <td height="30" align="right">&nbsp;</td>
                        <td height="30" class="bigtext">&nbsp;
                          <input type="submit" value=" 保 存 设 置 " /> 
                          &nbsp;&nbsp;&nbsp;</td>
                      </tr>
                    </table>
                    
                  </form>
                  </td>
                </tr>
              </table></td>
            </tr>
          </table></td>
        </tr>
      
    </table></td>
  </tr>
</table>
</body>
</html>
<?php mysql_close($link);?>
